#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
using ll=long long;
const int N=110;
int n;
ll tc,tm;
ll a[N],b[N],c[N];
bool check(ll mid){
	ll minn=max(1-tm+mid,0ll),maxn=min(tc-1,mid);
	
	for(int i=1;i<=n;i++)
	{
		double l=b[i]-a[i];
		double r=c[i]-a[i]*tc-b[i]*tm+b[i]*mid;
		if(l==0 && r<0)
			return false;
		else if(l>0)
			maxn=min(maxn,(ll)floor(r/l));
		else if(l<0)
			minn=max(minn,(ll)ceil(r/l));
	}
	return minn<=maxn;
}
void solve()
{
	
	
	cin>>n>>tc>>tm;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	ll left=0,right=tc+tm-2;
	while(left<right)
	{
		ll mid=left+(right-left)/2;
		if(check(mid))
		{
			right=mid;
		}
		else{
			left=mid+1;
		}
	}
	cout<<left<<endl;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}
